home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
util
/
rexx
/
addrexx11.lha
/
addrexx
/
addrexx.rexx
< prev
Wrap
OS/2 REXX Batch file
|
2000-08-31
|
4KB
|
166 lines
/*
** $VER: addrexx.rexx 1.1 (31.8.00) Rolf Max Rotvel
*/
call addlib('rexxreqtools.library', 0, -30, 0)
call addlib('rexxsupport.library', 0, -30, 0)
call addlib('locale.library', 0, -30, 0)
nl = '0a'x
fallbackeditor = 'c:ed'
center = 'rtez_flags=ezreqf_centertext'
editor = ''
maxsize = 500
title = 'Addrexx 1.1'
dir = arg(1)
res = pragma('d', dir)
if res = '' then call exitreq('Error reading directory'nl||dir)
if (upper(dir) = 'ENV:' | (dir = '' & upper(res) = 'ENV:')) then env? = 1
else env? = 0
show? = 0
do forever
if ~show? then do
file = rtfilerequest(,, title, 'Show')
call rtfreefilebuffer()
if file = '' then exit
if env? then do
envfile = 'ENV:'file
envarcfile = 'ENVARC:'file
end
end
show? = show()
end
SHOW:
if ~open('tmp', file, 'r') then do
if ~newentry(file) then return 0
return 1
end
txt = strip(readch('tmp', maxsize), 'b', ' 'nl)
call close('tmp')
parse var txt chk (nl) .
do i = 1 to min(length(chk), 5)
if ~isprint(substr(chk, i, 1)) then call exitreq('File is not ascii'nl||file)
end
ans = rtezrequest(txt, 'Ok|_Ed|_New|_Ren|_Del|_Prt|Quit', file)
select
when ans = 1 then return 0
when ans = 2 then call editor()
when ans = 3 then call newentry()
when ans = 4 then call renameentry()
when ans = 5 then do
if ~deleteentry() then return 0
end
when ans = 6 then call print()
otherwise exit
end
return 1
EDITOR:
if editor = '' then do
if open('tmp', 'env:editor', 'r') then do
editor = readln('tmp')
call close('tmp')
end
if editor = '' then editor = fallbackeditor
end
if env? then status = statef(file)
signal on failure
address command editor '"'file'"'
signal off failure
if env? then do
if statef(file) ~= status then do
if rtezrequest(envfile' has changed'nl'Save to ENVARC:?', 'Ok|Cancel', title, center) then do
if ~open('to', envarcfile, 'w') then call exitreq('Error writing'nl||envarcfile)
if ~open('from', file, 'r') then call exitreq('Error reading'nl||envfile)
call writech('to', readch('from', 65535))
call close('to')
call close('from')
end
end
end
return
NEWENTRY:
newentry = arg(1)
if newentry ~= '' then newentrytxt = 'Create new file?'
else newentrytxt = 'Enter name'
newfile = rtgetstring(newentry, newentrytxt)
if newfile ~= '' & rtresult ~= 0 then do
file = newfile
call editor()
end
else do
if newentry ~= '' then return 0
end
return 1
RENAMEENTRY:
newfile = rtgetstring(file, 'Enter new name')
if newfile ~= '' & rtresult ~= 0 then do
if newfile ~= file then do
if ~rename(file, newfile) then call exitreq('Error renaming'nl||file)
if env? then do
envarcnewfile = 'ENVARC:'newfile
if rtezrequest('Rename 'envarcfile||nl' to 'envarcnewfile'?', 'Ok|Cancel', title, center) then do
if ~rename(envarcfile, envarcnewfile) then call exitreq('Error renaming'nl||envarcfile)
envarcfile = envarcnewfile
end
envfile = 'ENV:'newfile
end
file = newfile
end
end
return
DELETEENTRY:
if rtezrequest('Delete'nl||file'?', 'Ok|Cancel', title, center) then do
if ~delete(file) then call exitreq('Error deleting'nl||file)
if env? then do
if exists(envarcfile) then do
if rtezrequest('Delete'nl||envarcfile'?', 'Ok|Cancel', title, center) then do
if ~delete(envarcfile) then call exitreq('Error deleting'nl||envarcfile)
return 0
end
end
end
else return 0
end
return 1
PRINT:
address command 'run >nil: copy "'file'" PRT:'
return
EXITREQ:
call rtezrequest(arg(1),, title, center)
exit
FAILURE:
call exitreq('Error running editor'nl||editor)
return